package com.ymatou.iapi.liveseller.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.ymatou.iapi.liveseller.parameter.AddProductsToLiveByAdminBean;
import com.ymatou.iapi.liveseller.service.AddProductsToLiveByAdminCall;
import com.ymatou.iapi.m.couponservice.parameter.productCodes;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.AddAgentProductCallService;
import com.ymttest.business.service.LiveRoomCallService;
import com.ymttest.business.service.ProductCallService;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.database.annotation.SqlMapperFactory;
import com.ymttest.database.model.LiveRoom;
import com.ymttest.database.model.Userinfo;
import com.ymttest.database.sqlwapper.JUserWapper;
import com.ymttest.database.sqlwapper.LiveRoomWapper;

import oracle.net.aso.a;
import oracle.net.aso.b;

/**
 * 添加商品到直播 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_AddProductsToLiveByAdmin {
	private static AddProductsToLiveByAdminBean AddProductsToLiveByAdminBean;
	private static AddProductsToLiveByAdminCall AddProductsToLiveByAdminCall;
	private static LiveRoomWapper liveRoomWapper;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("添加商品到直播");
	}

	@Before
	public void caseUp() {
		AddProductsToLiveByAdminBean = new AddProductsToLiveByAdminBean();
		AddProductsToLiveByAdminCall = new AddProductsToLiveByAdminCall();
		liveRoomWapper = new LiveRoomWapper();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(AddProductsToLiveByAdminCall.getOpurl());
		liveRoomWapper=null;
	}

	@After
	public void caseDown() {
		
		Logger.end();
	}

	private void verifyDB(Integer liveid, String pid, Integer uid,Integer PutawayCount,Integer LiveProudctNum) throws Exception {
		List<Map> listm = liveRoomWapper.selectLiveproductByIdAndPid(liveid, pid);
		Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
		Map pinfo = listm.get(0);
		Logger.verifyEquals(uid, pinfo.get("UserId"), "验证用户id");
		// 加入默认可售
		Logger.verifyEquals(1, pinfo.get("Status"), "验证Status");
		// 加入默认非置顶
		Logger.verifyEquals(false, pinfo.get("IsTop"), "验证IsTop");
		//默认false
		Logger.verifyEquals(false, pinfo.get("linkword"), "验证linkword");
		LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(liveid);
		Logger.verifyEquals(PutawayCount, liveroom.getPutawayCount(), "验证PutawayCount");
		Logger.verifyEquals(LiveProudctNum, liveroom.getLiveProductNum(), "验证LiveProductNum");
	}
	
	private void verifyDBRandHitNum(Integer liveid, String pid, Integer uid,Integer PutawayCount,Integer LiveProudctNum) throws Exception {
		List<Map> listm = liveRoomWapper.selectLiveproductByIdAndPid(liveid, pid);
		Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
		Map pinfo = listm.get(0);
		Logger.verifyEquals(uid, pinfo.get("UserId"), "验证用户id");
		// 加入默认可售
		Logger.verifyEquals(1, pinfo.get("Status"), "验证Status");
		//默认RandHitNum为1或者0
		int pi = Integer.parseInt(pinfo.get("RandHitNum").toString());
		Logger.verifyEquals(true,pi==1||pi==0, "验证RandHitNum默认为1或者0");
		// 加入默认非置顶
		Logger.verifyEquals(false, pinfo.get("IsTop"), "验证IsTop");
		//默认false
		Logger.verifyEquals(false, pinfo.get("linkword"), "验证linkword");
		LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(liveid);
		Logger.verifyEquals(PutawayCount, liveroom.getPutawayCount(), "验证PutawayCount");
		Logger.verifyEquals(LiveProudctNum, liveroom.getLiveProductNum(), "验证LiveProductNum");
	}
	/** 验证是否是万能链
	 * @param liveid
	 * @param pid
	 * @param uid
	 * @param PutawayCount
	 * @param LiveProudctNum
	 * @param isLinkword 是否是万能链 链接|专拍|直播专拍|直播专用|连接
	 * @throws Exception
	 */
	private void verifyDB(Integer liveid, String pid, Integer uid,Boolean isLinkword) throws Exception {
		List<Map> listm = liveRoomWapper.selectLiveproductByIdAndPid(liveid, pid);
		Logger.verifyEquals(1, listm.size(), "验证商品记录加入到数据库");
		Map pinfo = listm.get(0);
		Logger.debug(pinfo);
		Logger.verifyEquals(uid, pinfo.get("UserId"), "验证用户id");
		// 加入默认可售
		Logger.verifyEquals(1, pinfo.get("Status"), "验证Status");
		// 加入默认非置顶
		Logger.verifyEquals(false, pinfo.get("IsTop"), "验证IsTop");
		//验证是否是万能链
		Logger.verifyEquals(isLinkword, pinfo.get("linkword"), "验证linkword");
		LiveRoom liveroom = liveRoomWapper.selectLiveRoomById(liveid);
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_001() {
		Logger.start(true, "添加商品到直播成功");
		try {

			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));

			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("200", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			verifyDB(createlive.getId(), pid, uinfo.getUserId(),1,1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_002() {
		Logger.start(true, "不输入liveid失败");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));

			// AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("400", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			Logger.verifyIsContains("直播Id参数错误", AddProductsToLiveByAdminCall.getString("Msg"), "验证Msg");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	@Test
	@Category({ P3.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_005() {
		Logger.start(true, "不输入ProductId失败");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));

			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			// ProductIdList.add(pid);
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("400", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			Logger.verifyIsContains("必须选择至少一个商品", AddProductsToLiveByAdminCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_007() {
		Logger.start(true, "添加不存在商品到直播后查询直播列表不会显示");
		try {
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(null));
			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add("123");
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("201", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			// 待加入的商品全部不存在。
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_009() {
		Logger.start(true, "status9直播推流结束添加商品失败");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 9);
			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("201", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			Logger.verifyEquals("直播已关闭或已结束", AddProductsToLiveByAdminCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_010() {
		Logger.start(true, "status7系统关闭添加商品失败");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 7);
			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("201", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			Logger.verifyEquals("直播已关闭或已结束", AddProductsToLiveByAdminCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_011() {
		Logger.start(true, "status8未推流关闭直播添加商品失败");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 8);
			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("201", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			Logger.verifyEquals("直播已关闭或已结束", AddProductsToLiveByAdminCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P2.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_012() {
		Logger.start(true, "status10运营关闭直播添加商品失败");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			liveRoomWapper.updateLiveRoomPushStatus(createlive.getId(), 10);
			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("201", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			Logger.verifyEquals("直播已关闭或已结束", AddProductsToLiveByAdminCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_013() {
		Logger.start(true, "添加多个商品到直播成功");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid);
			String pid2 =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid2);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));

			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			ProductIdList.add(pid2);
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("200", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			for (String pids : ProductIdList) {
				verifyDB(createlive.getId(), pids, uinfo.getUserId(),ProductIdList.size(),ProductIdList.size());
			}

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	//耗时过长 手工执行
	public void Tc_AddProductsToLiveByAdmin_014() {
		Logger.start(true, "添加商品超限失败");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			List<String> ProductIdList = new ArrayList<>();
			int count = 51;
			for (int i = 0; i < count; i++) {
				String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			
			Logger.verifyEquals("201", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			Logger.verifyEquals("待加入商品已超出直播商品上限", AddProductsToLiveByAdminCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	@Ignore
	//耗时过长 手工执行
	public void Tc_AddProductsToLiveByAdmin_015() {
		Logger.start(true, "多次添加商品超限失败");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			List<String> ProductIdList = new ArrayList<>();
			List<String> ProductIdList2 = new ArrayList<>();
			int count = 26;
			for (int i = 0; i < count; i++) {
				String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
				Logger.comment("创建商品：" + pid);
				ProductIdList.add(pid);
			}
			
			for (int i = 0; i < count; i++) {
				String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
				Logger.comment("创建商品：" + pid);
				ProductIdList2.add(pid);
			}
			
			
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("200", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList2);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("201", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			Logger.verifyEquals("待加入商品已超出直播商品上限", AddProductsToLiveByAdminCall.getString("Msg"), "验证Msg");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_016() {
		Logger.start(true, "重复添加商品到直播之会有1条记录");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
//			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			
			
			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("200", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			verifyDB(createlive.getId(), pid, uinfo.getUserId(),1,1);
		} catch (Exception e) {
			Logger.fail(e);
			
		}
	}
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_017() {
		Logger.start(true, "添加万能链商品到直播成功");
		try {
//			链接|专拍|直播专拍|直播专用|连接
			List<String> lw=Arrays.asList("链接","专拍","直播专拍","直播专用","连接");
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			AddSellerProductRequest addpro = ProductManagerCallServiceV3.initAddSellerProductRequest(uinfo.getUserId());
			List<String> pids=new ArrayList<String>();
			for (String key : lw) {
				addpro.getProduct().setProductName(lw.get(new Random().nextInt(lw.size()))+addpro.getProduct().getProductName());
				String pid =ProductManagerCallServiceV3.AddSellerProduct(addpro);
				pids.add(pid);
			}
//			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pids);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			for (String tpid : pids) {
				AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
				List<String> ProductIdList = new ArrayList<>();
				ProductIdList.add(tpid);
				AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
				AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
				AddProductsToLiveByAdminCall.callService();
				Logger.verifyEquals("200", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
				verifyDB(createlive.getId(), tpid, uinfo.getUserId(),true);
				
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_018() {
		Logger.start(true, "添加商品到直播成功,商品落库时增加字段RandHitNum作为流量基数");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			Logger.comment("创建商品：" + pid);
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));

			
			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("200", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			Thread.sleep(2000);
			verifyDBRandHitNum(createlive.getId(), pid, uinfo.getUserId(),1,1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_019() {
		Logger.start(true, "运营下架的商品，可以被添加进直播间");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			//新建下架商品
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
//			ProductManagerCallServiceV2.UpdateProductCheckStatus(uinfo.getUserId(), pid, -1, "a");
			ProductManagerCallServiceV2.batchSetProductOffSale( Arrays.asList(pid),uinfo.getUserId());
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));
			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("200", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			Thread.sleep(2000);
			verifyDBRandHitNum(createlive.getId(), pid, uinfo.getUserId(),1,1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_AddProductsToLiveByAdmin_020() {
		Logger.start(true, "运营下架的商品，可以被添加进直播间");
		try {
			List<Userinfo> list = new JUserWapper().select1KSeller();
			Userinfo uinfo = list.get(0);
			//SqlMapperFactory.getIntergratedProductMapper().updateProductoffSale(uinfo.getUserId());
			
			//新建下架商品
			String pid =ProductManagerCallServiceV2.getNewProductId(uinfo.getLoginId(), uinfo.getUserId(), 10);
			ProductManagerCallServiceV2.UpdateProductCheckStatus(uinfo.getUserId(), pid, 0, "a");
			
			LiveRoom createlive = LiveRoomCallService.CreateSellerLive(LiveRoomCallService.initCreatesellerliveBean(uinfo));

			AddProductsToLiveByAdminBean.setLiveId(createlive.getId());
			List<String> ProductIdList = new ArrayList<>();
			ProductIdList.add(pid);
			AddProductsToLiveByAdminBean.setProductIdList(ProductIdList);
			AddProductsToLiveByAdminCall.setData(AddProductsToLiveByAdminBean);
			AddProductsToLiveByAdminCall.callService();
			Logger.verifyEquals("200", AddProductsToLiveByAdminCall.getString("Code"), "验证Code");
			Thread.sleep(2000);
			verifyDBRandHitNum(createlive.getId(), pid, uinfo.getUserId(),1,1);
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	
	
}